/**
 * Created by wk on 2017/10/12.
 */
//var obj = JSON.parse(localStorage.getItem('obj'));
(function() {
	var app = angular.module('App',

			['searchPageApp','hostMonitorApp','chainmonitorApp','assetManagementApp','processMonitorApp',
				'warningNoticeApp','ConfigManagementApp','warningNoticeReleaseApp','autoDiscoveryApp','MicroServicesManageApp',
				'WarningConfigApp','messageMiddlewareMonitorApp','cacheMonitorApp',
				'distributeddatabasemonitorApp','WhiteListConfigApp',
				'roleAndAuthorityManagementApp','configurationCollectionApp',
				'WarningPersonalizedConfigApp',"errorchainApp",'oracleMonitorApp']);
	var location = (window.location + '').split('/');
	var basePath = location[0] + '//' + location[2] + '/' + location[3];
	app
			.controller(
					'IndexController',
					function($scope, $http, $log) {
						var indexController = this;
						var controller = this;
						this.currentTab = null;
						// 请求后台Menu数据
						$http
								.get(basePath + '/MenuIndex')
								.success(
										function(data) {
											menuArray = data;
											for (var i = 0; i < menuArray.length; i++) {
												if (menuArray[i].url != null) {
													// 拼接basePath
													menuArray[i].url = basePath
															+ menuArray[i].url;
												}
												if (menuArray[i].children != null) {
													for (var j = 0; j < menuArray[i].children.length; j++) {
														if (menuArray[i].children[j].url != null) {
															// 拼接basePath
															menuArray[i].children[j].url = basePath
																	+ menuArray[i].children[j].url;
														}
														
														if(menuArray[i].children[j].children != null){
															for(var k = 0; k < menuArray[i].children[j].children.length; k++){
																// 拼接basePath
																menuArray[i].children[j].children[k].url = basePath
																		+ menuArray[i].children[j].children[k].url;
															}
														}
													}
												}
											}
											// 生成Menu数组
											indexController.tabs = menuArray;
											$scope.tabs = menuArray;
											indexController.currentChild = {
													name : menuArray[0].children[0].name,
													url : menuArray[0].children[0].url,
													children : null
												};
										}).error(function() {
									$log.info('菜单部分出现异常！');
								});
						//第一层目录
						$scope.setCurrentContent = function(child, tab) {
							controller.currentTab = tab;
							controller.currentChild = child;
						}
						
						//第二层目录
						$scope.setCurrentContent2 = function(child, tab) {
							controller.currentTab = tab;
							controller.currentChild = child;
						}
						
						//第三层目录
						$scope.setCurrentContent3 = function(child, tab) {
							controller.currentTab = tab;
							controller.currentChild = child;
						}
						
						//主机地址
						$scope.getAppBasePath = function(){
							return basePath;
						}
					});
})();